
'''原始代码'''

def a(x, debug=False):
    if debug:
        print('Calling a')
    print(x)

def b(x, y, z, debug=False):
    if debug:
        print('Calling b')
    print(x, y, z)

def c(x, y, debug=False):
    if debug:
        print('Calling c')
    print(x, y)

'''重构代码：避免一些重复代码'''

from functools import wraps
import inspect

def optional_debug(func):
    if 'debug' in inspect.getargspec(func).args:
        raise TypeError('debug argument already defined')

    @wraps(func)
    def wrapper(*args, debug=False, **kwargs):
        if debug:
            print('Calling', func.__name__)
        return func(*args, **kwargs)
    return wrapper

@optional_debug
def a1(x):
    print(x)

@optional_debug
def b1(x, y, z):
    print(x, y, z)

@optional_debug
def c1(x, y):
    print(x, y)

def recipe1():
    print(f"{a(1) = }")
    print(f"{a1(2) = }")
    print(f"{a1(3, debug = True) = }")

def main():
    print('recipe1'.center(20, '*'))
    recipe1()


if __name__ == '__main__':
    main()           